<?php  
session_start();
include("../connect.php");
header('content-type:text/html;charset=utf-8');   
?>
			<?php
		if($_SESSION['username']==""&&$_SESSION['username']!="admin"){
			header('location:../index.php');
		}
		 
		 ?>	
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
		 crossorigin="anonymous"></script>
		<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
		 crossorigin="anonymous"></script>
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
		 crossorigin="anonymous">
		<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
		 crossorigin="anonymous"></script>
	</head>
	<body>
		<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
		  <a class="navbar-brand" href="#">寻书网后台</a>
		  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
		    <span class="navbar-toggler-icon"></span>
		  </button>
		  <div class="collapse navbar-collapse" id="navbarText">
		    <ul class="navbar-nav mr-auto">
		      <li class="nav-item active">
		        <a class="nav-link" href="javascript:;">您好 <span> <?php echo $_SESSION['username']?></span></a>
		      </li>
			  <li class="nav-item">
			    <a class="nav-link" data-toggle="modal" data-target="#exampleModal">修改密码</a>
			  </li>
		      <li class="nav-item">
		        <a class="nav-link" href="javascript:;"  onclick="logout()">退出</a>
		      </li>
		    </ul>
		    <span class="navbar-text">
		     欢迎来到寻书网后台管理系统
		    </span>
		  </div>
		</nav>
	<div class="container">
		<div class="row">
		  <div class="col-3">
		    <div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
		      <a class="nav-link active" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home" aria-selected="true">用户管理</a>
		      <a class="nav-link" id="v-pills-profile-tab" data-toggle="pill" href="#v-pills-profile" role="tab" aria-controls="v-pills-profile" aria-selected="false">书籍管理</a>
		      <a class="nav-link" id="v-pills-messages-tab" data-toggle="pill" href="#v-pills-messages" role="tab" aria-controls="v-pills-messages" aria-selected="false">求书者留言</a>
		    </div>
		  </div>
		  <div class="col-9">
		    <div class="tab-content" id="v-pills-tabContent">
                <!-- 用户 -->
		      <div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">
				  <div class="row">
					   <?php
								$sql="select * from userinfo   order by id DESC";
					  			$result=mysqli_query($conn,$sql);
					  			while($data=mysqli_fetch_array($result))
					  {
					  ?>
				  	<div class="card" style="margin: 10px;">
				  	  <div class="card-header">
				  	    <?php echo $data['username']?>
				  	  </div>
				  	  <div class="card-body">
				  	     <p class="card-text">电话：<?php echo $data['tel']?></p>
				  	    <p class="card-text">邮箱：<?php echo $data['Email']?></p>
				  	    <a href="del.php?id=<?php echo $data['id']?>&k=userinfo" onClick="return confirm('真的要删除？')"  class="btn btn-danger">删除</a>
				  	  </div>
				  	</div>
					<?php
					}
						?>
				  </div> 
              </div>
              <!-- 书籍 -->
		      <div class="tab-pane fade" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">
				  <div class="row">
					    <?php
					  			$sql="select * from  bookinfo  order by id DESC";
					  			$result=mysqli_query($conn,$sql);
					  			while($data=mysqli_fetch_array($result))
					  {
					  ?>
				  	<div class="card" style="margin: 10px;">
				  	  <div class="card-header">
				  	    《<?php echo $data['bookname']?>》
				  	  </div>
				  	  <div class="card-body">
				  	     <p class="card-text">发布时间：<?php echo $data['rtime']?></p>
				  	    <p class="card-text">发布者：<?php echo $data['username']?></p>
				  	    <a href="del.php?id=<?php echo $data['id']?>&k=bookinfo" onClick="return confirm('真的要删除？')"  class="btn btn-danger">删除</a>
				  	  </div>
				  	</div>
					<?php
					}
						?>
				  </div>
              </div>
              <!-- 求书者 -->
		      <div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">
				  <div class="row">
					   <?php
					   $sql="select * from demand order by id DESC";
					   $result=mysqli_query($conn,$sql);
					  while($data=mysqli_fetch_array($result))
					  {
					  ?>
				  	<div class="card border-primary " style=" margin: 10px;">
				  	  <div class="card-header"><?php echo $data['username']?></div>
				  	  <div class="card-body ">
				  	    <h5 class="card-title">《<?php echo $data['title']?>》</h5>
				  	    <p class="card-text">内容：<?php echo $data['content']?></p>
						 <a href="del.php?id=<?php echo $data['id']?>&k=demand" onClick="return confirm('真的要删除？')" class="btn btn-danger">删除</a>
				  	  </div>
					  <div class="card-footer "><small class="text-muted"><?php echo $data['time']?></small></div>
				  	</div>
					  <?php 
							    }
							      ?>
				  </div>
			  </div>
		    </div>
		  </div>
		</div>
		</div>
		<?php  
		if ($_GET['action'] == 'pwd')
		{
		 $pwd1=$_POST['pwd1'];
		$pwd2=$_POST['pwd2'];
		$pwd3=$_POST['pwd3'];
		if( $pwd1==$_SESSION[pwd])
		{
				if( $pwd2==$pwd3)
				{
				  $SQL="update admin set  pwd='".$pwd3."' where username='".$_SESSION[username]."'"; 
					$sql=mysqli_query( $conn,$SQL);
				   $_SESSION[pwd]=$pwd3; 
					echo "<script>alert('恭喜，操作成功!');window.history.back();</script>";
					exit;
				 }
				else
				{ echo "<script>alert('两次输入的新密码不同!');window.history.back();</script>";
				}
		}
		else
		{  echo "<script>alert('旧密码错误!');window.history.back();</script>";
		}
		}
		?>
		<!-- Modal -->
		<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		      <div class="modal-header">
		        <h5 class="modal-title" id="exampleModalLabel">修改密码</h5>
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
		          <span aria-hidden="true">&times;</span>
		        </button>
		      </div>
		      <div class="modal-body" id="admin">
				<form method="post" name="login" action="admin.php?action=pwd">
				  <div class="form-group">
				  <label for="exampleInputPassword1">旧密码</label>
				  <input type="password" name="pwd1"  class="form-control" required="required" id="exampleInputPassword1">
				  </div>
				  <div class="form-group">
				    <label for="exampleInputPassword2">新密码</label>
				    <input type="password" name="pwd2"  class="form-control" required="required" id="exampleInputPassword2">
				  </div>
				  <div class="form-group">
				   <label for="exampleInputPassword3">重新输入新密码</label>
				   <input type="password" name="pwd3"  class="form-control" required="required" id="exampleInputPassword3">
				  </div>
					 <button type="submit" class="btn btn-primary">提交</button>
				</form>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
		      </div>
		    </div>
		  </div>
		</div>
		<!-- 模态框 -->
	</body>
	
</html>
<script type="text/javascript">
   function logout()
			{
			   	if(confirm("确定要退出本系统吗??"))
			   	{
            		window.parent.location="../out.php";   
			   	}
			} 
</script>